#include "ZYFPImageLoader.h"
#include "ThreadSafeZYFPFactory.h"

ZYFPImageLoader::ZYFPImageLoader() : QQuickImageProvider(QQuickImageProvider::Image)
{  }

QImage ZYFPImageLoader::requestImage(const QString& id, QSize* size, const QSize& requestedSize)
{
	Q_UNUSED(requestedSize);
	QImage img;
	zyfp_handle* ph = ThreadSafeZYFPFactory::giveMeHandle();
	if (!ph) return img;
	ssize_t k = zyfp_open(ph, id.toLatin1().data());
	if (k < 0) return img;
	uchar* out;
	k = zyfp_readall(ph, (char**)&out);
	if (k > 0) {
		img.loadFromData(out, (int)k);
		free(out);
	}
	*size = img.size();
	return img;
}
